import axios from 'axios'
import qs from "qs"


const instance = axios.create({
  baseURL: 'http://123.207.32.32:8000/api/v1/',
  timeout: 1000 * 60,//20s

})
instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
// 请求拦截
instance.interceptors.request.use(config => {
  // config.data = qs.stringify(config.data)
  // console.log(config)
  return config
})
// 响应拦截。就是走then方法之前先执行响应拦截
instance.interceptors.response.use(res => {
  return res.data
})
export function get(url, params = {}) {
  return new Promise((resolve, reject) => {
    instance.get(url, {
      params: params
    }).then(res => resolve(res)).catch(err => reject(err))
  })
}

export function post(url, params) {
  return new Promise((resolve, reject) => {
    instance.post(url, qs.stringify(params))
    .then(res => resolve(res))
    .catch(err => reject(err))
  })
}
